package test_util

import (
	. "lambda"
	. "bridge/base"
	"reduce"
	"fmt"
)

var (
	ENV TestEnv
)

func ReduceFully(t Term) Primitive {
	return reduce.ReduceFully(t, ENV)
}

func Reduce(t Term) Term {
	return t.Reduce(ENV)
}

func MultiReduce(t Term, count int) Term {
	for i := 0; i < count; i++ {
		t = t.Reduce(ENV)
	}
	return t
}

type TestEnv struct{}

func (_ TestEnv) CallFunction(code uint64, args []Primitive) Primitive {
	switch code {
	case 1:
		return []byte{3}
	case 2:
		return args[1]
	case 3:
		return PrimByte(args[0][0] + args[1][0])
	}

	panic(fmt.Sprintf("bad code: %d", code))
}

func (_ TestEnv) CallPredicate(code uint64, args []Primitive) bool {
	switch code {
	case 1:
		return args[0][0] < args[1][0]
	}

	panic(fmt.Sprintf("bad code: %d", code))
}
